using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Card : Admin, IRequiresSessionState
{
	public bool amingdeleteflag = true;
	public bool amingckeckflag = true;
	private string m_Moment = "";
	private string merchar = "";
	private bool m_tag = true;
	private string linkhead = "";
	private string wherestr = "";
	private CardBll _card = null;
	protected DropDownList DropMoment;
	protected TextBox TextBox1;
	protected Button Button1;
	protected GridView GridView1;
	protected Label PagePanel;
	protected Button ButDel;
	protected Button ButSell;
	private CardBll m_card
	{
		get
		{
			CardBll card;
			if (this._card == null)
			{
				this._card = new CardBll();
				card = this._card;
			}
			else
			{
				card = this._card;
			}
			return card;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.amingckeckflag = base.admin.CheckAdminPower(107);
		this.amingdeleteflag = base.admin.CheckAdminPower(106);
		if (!base.admin.CheckAdminPower(104))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Card");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(106))
			{
				this.ButDel.Enabled = false;
				this.amingdeleteflag = false;
			}
			if (!base.admin.CheckAdminPower(107))
			{
				this.ButSell.Enabled = false;
				this.amingckeckflag = false;
			}
			this.BindList();
		}
	}
	protected void BindList()
	{
		int num = Fetch.GetID("page");
		if (num <= 0)
		{
			num = 1;
		}
		this.QuestString();
		int maxperpage = 15;
		if (this.GridView1.PageSize != 0)
		{
			maxperpage = Convert.ToInt32(this.GridView1.PageSize);
		}
		this.GridView1.DataSource = this.m_card.GetCards(num, maxperpage, this.wherestr, "");
		this.GridView1.DataBind();
		this.PagePanel.Text = this.m_card.GetPagePanel(this.linkhead);
	}
	protected void QuestString()
	{
		this.m_Moment = Fetch.Get("mt");
		if (this.m_Moment != string.Empty && this.m_tag)
		{
			this.DropMoment.SelectedValue = this.m_Moment;
		}
		else
		{
			this.m_Moment = this.DropMoment.SelectedValue;
		}
		if (this.m_Moment != "-1")
		{
			this.wherestr = this.wherestr + "and CardState=" + int.Parse(this.m_Moment).ToString() + " ";
			this.linkhead = this.linkhead + "&mt=" + this.m_Moment;
		}
		this.merchar = Fetch.Get("mc");
		if (this.merchar != string.Empty & this.m_tag)
		{
			this.TextBox1.Text = this.merchar;
		}
		else
		{
			this.merchar = this.TextBox1.Text;
		}
		if (this.merchar != string.Empty)
		{
			this.wherestr = this.wherestr + "and CardAgentName like '%" + this.merchar + "%' ";
			this.linkhead = this.linkhead + "&mc=" + base.Server.UrlEncode(this.merchar);
		}
		if (this.wherestr != "")
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "where");
		}
	}
	protected void DropMoment_OnChange(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void Button1_OnClick(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void DeleteCard(object sender, CommandEventArgs e)
	{
		if (base.admin.CheckAdminPower(106))
		{
			this.m_card.DeleteCard(Convert.ToInt32(e.CommandName));
			base.WriteLog("Delete", Language.GetAdminMsg("Log/ObjectID", e.CommandName.ToString()), "Card");
			this.BindList();
		}
		else
		{
			base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", e.CommandName.ToString()), "Card");
			base.WriteRightErrMsg();
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			DateTime now = DateTime.Now;
			DateTime.TryParse(gridViewRow.Cells[5].Text, out now);
			gridViewRow.Cells[5].Text = now.ToShortDateString();
			Literal literal = (Literal)gridViewRow.Cells[8].FindControl("CardState");
			Panel panel = (Panel)gridViewRow.Cells[9].FindControl("ModifyPanel");
			Panel panel2 = (Panel)gridViewRow.Cells[9].FindControl("ShowPanl");
			CheckBox checkBox = (CheckBox)gridViewRow.Cells[0].FindControl("chkSelect");
			string text = literal.Text;
			if (text != null)
			{
				if (!(text == "0"))
				{
					if (!(text == "1"))
					{
						if (!(text == "2"))
						{
							if (text == "3")
							{
								literal.Text = Language.Get("Shop/Card/Stutas3");
							}
						}
						else
						{
							literal.Text = Language.Get("Shop/Card/Stutas2");
							panel.Visible = false;
							panel2.Visible = true;
						}
					}
					else
					{
						literal.Text = Language.Get("Shop/Card/Stutas1");
						panel.Visible = false;
						panel2.Visible = true;
					}
				}
				else
				{
					literal.Text = Language.Get("Shop/Card/Stutas0");
				}
			}
			if (gridViewRow.Cells[1].Text == "1")
			{
				gridViewRow.Cells[1].Text = Language.Get("Shop/Card/Type1");
			}
			else
			{
				gridViewRow.Cells[1].Text = Language.Get("Shop/Card/Type0");
			}
			if (!this.amingckeckflag)
			{
				LinkButton linkButton = (LinkButton)gridViewRow.Cells[9].FindControl("btnSell");
				linkButton.Visible = false;
			}
			if (!this.amingdeleteflag)
			{
				LinkButton linkButton2 = (LinkButton)gridViewRow.Cells[9].FindControl("btnDelete");
				linkButton2.Visible = false;
			}
		}
	}
	protected void Sell_Click(object sender, CommandEventArgs e)
	{
		int num = 0;
		try
		{
			num = int.Parse(e.CommandName);
		}
		catch
		{
			return;
		}
		if (num > 0)
		{
			if (this.m_card.SellCard(num))
			{
				base.WriteLog("Check", Language.GetAdminMsg("Log/ObjectID", num.ToString()), "Card");
				this.BindList();
			}
		}
	}
	protected void ButSell_Click(object sender, EventArgs e)
	{
		string text = this.CheckNumList(base.Request["chk_select"]);
		if (text != "")
		{
			this.m_card.SellCard(text);
			base.WriteLog("Check", Language.GetAdminMsg("Log/ObjectID", text), "Card");
			this.BindList();
		}
	}
	protected void ButDel_Click(object sender, EventArgs e)
	{
		string text = this.CheckNumList(base.Request["chk_select"]);
		if (text != "")
		{
			this.m_card.DeleteCards(text);
			base.WriteLog("Delete", Language.GetAdminMsg("Log/ObjectID", text), "Card");
			this.BindList();
		}
	}
}
